package T1700;

/**
 * @Author cheng.song
 * @create 2022/2/24 13:41
 */
public class 球会落何处1706 {

    public static void main(String[] args) {
        int[][] grid =new int[][]{{1,1,1,1,1},{-1,-1,-1,-1,-1},{1,1,-1,1,1},{-1,-1,-1,-1,-1}} ;
        for (int i = 0; i < findBall(grid).length; i++) {
            System.out.println(findBall(grid)[i]);
        }
    }

    public static int[] findBall(int[][] grid) {
        int ballSize = grid[0].length;
        int height = grid.length;
        int[] ballResult = new int[ballSize];
        for (int i = 0; i < ballSize; i++) {
            int currentIndex = i;
            for (int currentLevel = 0; currentLevel < height; currentLevel++) {
                if(grid[currentLevel][currentIndex]==1 && currentIndex<ballSize-1 && grid[currentLevel][currentIndex+1]!=-1){
                    currentIndex++;
                }else if(grid[currentLevel][currentIndex]==-1 && currentIndex>0 && grid[currentLevel][currentIndex-1]!=1){
                    currentIndex--;
                }else{
                    ballResult[i] = -1;
                    break;
                }
                if(currentLevel==height-1){
                    ballResult[i] = currentIndex;
                }
            }
        }
        return ballResult;
    }

}
